<script type="text/javascript"><!--//--><![CDATA[//><!--

  
	var grid_reload = function() {
        $('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
    };
    
	
	
    $(document).ready(function() {
	
		
		
        // Create Datagrid
        $('#datagrid').datagrid(
        {
            url: gs_path + '/' + controller + '/getdata',
            queryParams: $('#fm_search').serializeObject(),
            height: 340,
            pagination: true,
            columns: [[
				{ field : 'ck', checkbox:true, width: 40, align: 'center' },
                { field: 'user_id', title: 'User ID', width: 120 },
                { field: 'password', title: 'Password', hidden: true },
                { field: 'user_name', title: 'User Name', width: 200 },
                { field: 'description', title: 'Deskripsi', width: 150 },
				{ field: 'department_name', title: 'Departement', width: 150 },
                { field: 'email', title: 'Email', width: 160 },
                { field: 'last_login', title: 'Login Terakhir'/*, formatter: function(val) { return (formatDate(val)); }*/, align: 'center', width: 140 },
                { field: 'status', hidden: true },
                { field: 'status_name', title: 'Status', align: 'center', width: 75 }
            ]]
        });
        
        // Set Action Button
        var buttons = [
                        // ----- >> Add Button
                        { label: 'Add', icon: 'add', onclick: function() {
                            var oSel = $('#datagrid').datagrid('getSelected'); 
                            
                            var $popup = openPopup({ title: '&nbsp;', 
                                width: 564,
                                height: 460,
                                url: gs_path + '/' + controller + '/create/' + (oSel == null ? '' : '?user_id=' + oSel.user_id),
                                buttons: [{
                                    text: 'Save',
                                    iconCls: 'icon-save',
                                    handler: function() {
                                        $('#form_popup').submitForm('/' + controller + '/ajax_post', { onComplete: function() { closePopup(); $('#datagrid').datagrid('reload'); } });
                                    }
                                }, {
                                    text: 'Close',
                                    iconCls: 'icon-cancel',
                                    handler: function() {
                                        closePopup();
                                    }
                                }],
                                onComplete: function(){ $('#form_popup').data('mode', 'create'); }
                             });
                            
                        }},
                        
                        // ----- >> Edit Button
					    { label: 'Edit', icon: 'edit', onclick: function() {
					        var oSel = $('#datagrid').datagrid('getSelected');
					        if (oSel == null) {
					            alert('Please select row!'); 
					        } else {

					            var $popup = openPopup({ title: '&nbsp;',
					                width: 564,
					                height: 460,
					                url: gs_path + '/' + controller + '/edit/?user_id=' + urlencode(oSel.user_id),
					                buttons: [{
					                    text: 'Save',
					                    iconCls: 'icon-save',
					                    handler: function() {
					                        $('#form_popup').submitForm('/' + controller + '/ajax_post', { onComplete: function() { closePopup(); $('#datagrid').datagrid('reload'); } });
					                    }
					                }, {
					                    text: 'Close',
					                    iconCls: 'icon-cancel',
					                    handler: function() {
					                        closePopup();
					                    }
                                    }],
					                    onComplete: function() { $('#form_popup').data('mode', 'edit'); }
					            });
					        } 
					    }},

					    // ----- >> Delete Button
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['user_id']);
							} 
						}}];
        setAction(buttons);
		
		
		$('#fm_search').focusFirst();
    });
//--><!]]></script>

    
<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
			    </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>